<template>
    <div class="address-list-item">
        <van-cell-group>
            <van-cell class="address-list-tel" :title="title" :value="tel" :border="false" />
            <van-cell class="address-list-text" :value="address" />
            <van-row class="radio-box" v-if="checkName">
                <van-radio class="radio" :name="checkName">默认地址</van-radio>
                <div class="icon">
                    <span @click="$router.push({name:'addressEdit', query: {id: id}})">
                        <van-icon name="records" />
                        <i class="icon-name">编辑</i>
                    </span>
                    <span @click="handleDelete(id)">
                        <van-icon name="delete" />
                        <i class="icon-name">删除</i>
                    </span>
                </div>
            </van-row>
        </van-cell-group>
    </div>
</template>

<script>
import { deleteAddressInfo } from '@/api/address/index.js'

export default {
    props: {
        id: Number,
        title: String,
        tel: String,
        checkName: [String, Number],
        address: String
    },
    data () {
        return {

        }
    },
    methods: {
        handleDelete (id) {
            this.$dialog.confirm({
                title: '确定删除？',
                message: '',
            }).then(() => {
                deleteAddressInfo(id).then((rst) => {
                    if (rst.status == 0) {
                        this.$emit('getData')
                        this.$toast(rst.message)
                    } else {
                        this.$toast(rst.message ? rst.message : '删除失败，请稍后再试')
                    }
                }).catch(() => {
                    this.$toast('删除失败，请稍后再试')
                })
            }).catch(() => {
                
            })
        }
    },
}
</script>

<style lang="scss" scoped>
.address-list-item {
    margin-bottom: 10px;
    .address-list-tel {
        padding: 8px 15px;
    }
    .address-list-text {
        padding: 0px 15px 10px;
        line-height: 20px;
    }
    .address-list-text.van-cell:not(:last-child)::after {
        right: 15px;
    }
    .radio-box {
        padding: 8px 15px;
        height: 20px;
        line-height: 20px;
        .radio {
            float: left;
            .van-radio__input {
                .van-icon {
                    vertical-align: top;
                }
            }
        }
        .icon {
            float: right;
            span {
                color: #333333;
                margin-left: 15px;
            }
            .van-icon {
                font-size: 18px;
                color: #999;
            }
            i {
                vertical-align: top;
                &.icon-name {
                    font-size: 13px;
                }
            }
        }
    }
}
</style>